<?php


namespace app\admin\controller;


use think\App;
use think\Controller;
use think\Db;
use think\facade\Log;

class CommonController extends Controller
{
    protected static $Page = 1;
    protected static $Limit = 10;
    public function __construct(App $app = null)
    {

        parent::__construct($app);
    }

    protected function GetRandStr($length){
        $str = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890';
        $randStr = str_shuffle($str);//打乱字符串
        $rands= substr($randStr,0,$length);
        return $rands;
    }
    protected function GetPermissionUser($user_id){
        $res=Db::table('user')
            ->alias('a')
            ->join('user_role b','a.id = b.user_id')
            ->join('role c','c.id = b.role_id')
            ->join('permission_role d','d.role_id = c.id')
            ->join('permission e','e.id = d.permission_id')
            ->where('a.delete_flag','=',0)
            ->where('a.status','=',0)
            ->where('b.delete_flag','=',0)
            ->where('b.status','=',0)
            ->where('c.delete_flag','=',0)
            ->where('c.status','=',0)
            ->where('d.delete_flag','=',0)
            ->where('d.status','=',0)
            ->where('e.delete_flag','=',0)
            ->where('e.status','=',0)
            ->where('a.id','=',$user_id)
            ->where('e.is_show','=',1)
            ->field('e.id as per_id,e.pid as p_id,e.name as per_name,e.info as per_info,e.route as per_route,e.title as per_title,e.icon as per_icon,e.menu_path as per_menu_path,e.menu_name as per_menu_name,e.component as per_component,e.is_show as per_is_show')
            ->select();
        return $res;
    }

    /**
     *
     * @return mixed
     * 获取用户id
     */
    public function getUserId($token){
        $jwtAuth=JwtAuth::getInstance();
        return $jwtAuth->setToken($token)->getUid();
    }


}